package com.ymatou.iapi.captcha.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.captcha.parameter.*;
import com.ymatou.iapi.captcha.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ValidateCodeServiceV2;
import com.ymttest.database.model.ValidationCode;
import com.ymttest.database.model.YmtValidationCode;
import com.ymttest.database.sqlwapper.YmtValidationCodeWapperV2;
import com.ymttest.utils.TestDataManager;
/**
*校验验证码用例
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GConfirmValidateCode{
	private static GConfirmValidateCodeBean GConfirmValidateCodeBean;
	private static GConfirmValidateCodeCall GConfirmValidateCodeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("校验验证码用例");
	}

	@Before
	public void caseUp() {
		GConfirmValidateCodeBean=new GConfirmValidateCodeBean();
		GConfirmValidateCodeCall=new GConfirmValidateCodeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(GConfirmValidateCodeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GConfirmValidateCode_001() {
		Logger.start(true,"校验图片验证码验证通过");
		try {
			
			GetValidateCodeBean getvalidatecodeBean = new ValidateCodeServiceV2().setGetValidateCodeBean(1, 640, 4,TestDataManager.getRandomUUID().toString(), 99);
			GetValidateCodeCall getValidateCodeCall = new ValidateCodeServiceV2().GetValidateCode(getvalidatecodeBean);
			
			GConfirmValidateCodeBean.setValidateCode(getValidateCodeCall.getValidateCode());
			GConfirmValidateCodeBean.setGuid(getvalidatecodeBean.getActionUser());
			
			GConfirmValidateCodeCall.setData(GConfirmValidateCodeBean);
			GConfirmValidateCodeCall.callService();

			Logger.verifyEquals("True", GConfirmValidateCodeCall.getReturnData(), "验证返回code");
		
			// 验证数据库落地正确
			ValidationCode validationCode = new YmtValidationCodeWapperV2().getByActionUserAndValidateType(getvalidatecodeBean.getActionUser(), getvalidatecodeBean.getValidateType()).get(0);
			Logger.verifyEquals(getValidateCodeCall.getValidateCode(), validationCode.getCode(), "验证数据库表Ymt_ValidationCode中字段sValidateCode");
			Logger.verifyEquals(1, validationCode.getStatus(), "验证数据库表Ymt_ValidationCode中字段Ivalidatestatus");
			Logger.verifyEquals(200, validationCode.getResult(), "验证数据库表Ymt_ValidationCode中字段iValidateResult");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GConfirmValidateCode_002() {
		Logger.start(true,"校验图片验证码,验证码错误失败");
		try {
			
			GetValidateCodeBean getvalidatecodeBean = new ValidateCodeServiceV2().setGetValidateCodeBean(1, 640, 4,TestDataManager.getRandomUUID().toString(), 99);
			GetValidateCodeCall getValidateCodeCall = new ValidateCodeServiceV2().GetValidateCode(getvalidatecodeBean);
			
			GConfirmValidateCodeBean.setValidateCode(getValidateCodeCall.getValidateCode()+1);
			GConfirmValidateCodeBean.setGuid(getvalidatecodeBean.getActionUser());
			
			GConfirmValidateCodeCall.setData(GConfirmValidateCodeBean);
			GConfirmValidateCodeCall.callService();

			Logger.verifyEquals("False", GConfirmValidateCodeCall.getReturnData(), "验证返回code");
		
			// 验证数据库落地正确
			ValidationCode validationCode = new YmtValidationCodeWapperV2().getByActionUserAndValidateType(getvalidatecodeBean.getActionUser(), getvalidatecodeBean.getValidateType()).get(0);
			Logger.verifyEquals(getValidateCodeCall.getValidateCode(), validationCode.getCode(), "验证数据库表Ymt_ValidationCode中字段sValidateCode");
			Logger.verifyEquals(0, validationCode.getStatus(), "验证数据库表Ymt_ValidationCode中字段Ivalidatestatus");
			Logger.verifyEquals(0, validationCode.getResult(), "验证数据库表Ymt_ValidationCode中字段iValidateResult");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GConfirmValidateCode_003() {
		Logger.start(true,"不输入验证码失败");
		try {
			
			GetValidateCodeBean getvalidatecodeBean = new ValidateCodeServiceV2().setGetValidateCodeBean(1, 640, 4,TestDataManager.getRandomUUID().toString(), 99);
			GetValidateCodeCall getValidateCodeCall = new ValidateCodeServiceV2().GetValidateCode(getvalidatecodeBean);
			
//			GConfirmValidateCodeBean.setValidateCode(getValidateCodeCall.getValidateCode()+1);
			GConfirmValidateCodeBean.setGuid(getvalidatecodeBean.getActionUser());
			
			GConfirmValidateCodeCall.setData(GConfirmValidateCodeBean);
			GConfirmValidateCodeCall.callService();

			Logger.verifyEquals("False", GConfirmValidateCodeCall.getReturnData(), "验证返回code");
		

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GConfirmValidateCode_004() {
		Logger.start(true,"不输入guid失败");
		try {
			
			GetValidateCodeBean getvalidatecodeBean = new ValidateCodeServiceV2().setGetValidateCodeBean(1, 640, 4,TestDataManager.getRandomUUID().toString(), 99);
			GetValidateCodeCall getValidateCodeCall = new ValidateCodeServiceV2().GetValidateCode(getvalidatecodeBean);
			
			GConfirmValidateCodeBean.setValidateCode(getValidateCodeCall.getValidateCode()+1);
//			GConfirmValidateCodeBean.setGuid(getvalidatecodeBean.getActionUser());
			
			GConfirmValidateCodeCall.setData(GConfirmValidateCodeBean);
			GConfirmValidateCodeCall.callService();

			Logger.verifyEquals("False", GConfirmValidateCodeCall.getReturnData(), "验证返回code");
		

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GConfirmValidateCode_005() {
		Logger.start(true,"输入不存在guid失败");
		try {
			
			GetValidateCodeBean getvalidatecodeBean = new ValidateCodeServiceV2().setGetValidateCodeBean(1, 640, 4,TestDataManager.getRandomUUID().toString(), 99);
			GetValidateCodeCall getValidateCodeCall = new ValidateCodeServiceV2().GetValidateCode(getvalidatecodeBean);
			
			GConfirmValidateCodeBean.setValidateCode(getValidateCodeCall.getValidateCode()+1);
			GConfirmValidateCodeBean.setGuid(TestDataManager.getRandomUUID().toString());
			
			GConfirmValidateCodeCall.setData(GConfirmValidateCodeBean);
			GConfirmValidateCodeCall.callService();

			Logger.verifyEquals("False", GConfirmValidateCodeCall.getReturnData(), "验证返回code");
		

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}